package xyz.eden.cloud.common.mybatis.support.fill.context;

import com.alibaba.ttl.TransmittableThreadLocal;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

public class MetaDataContext {

    protected static final TransmittableThreadLocal<OperateInfo> OPERATE_CONTEXT = new TransmittableThreadLocal<>();

    public static void clearOperate() {
        OPERATE_CONTEXT.remove();
    }

    public static OperateInfo getOperate() {
        return OPERATE_CONTEXT.get();
    }

    /**
     * 设置操作者
     *
     * @param operate
     */
    public static void setOperate(OperateInfo operate) {
        OPERATE_CONTEXT.set(operate);
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class OperateInfo {
        /**
         * 操作者
         */
        private String username;
        /**
         * 操作者 IP
         */
        private String operateIp;
        /**
         * 操作时间
         */
        private Long operateTime;
    }
}
